unit uniEnemyAircraft_Straight;

interface

uses
  uniEnemyAircraft,
  Classes;

type
  { EnemyAircraft_Straight }

  EnemyAircraft_Straight = class(EnemyAircraft)
  public
    constructor Create(et: EnemyType; p: array of Single; randFact: Single = 1.0);
    destructor Destroy; override;

    procedure update; override;
    procedure init; overload; override;
    procedure init(p: array of Single; randFact: Single = 1.0); overload; override;
    procedure calcShootInterval; override;
    procedure move; override;
  end;


implementation

uses
  uniConfig,
  uniGlobal,
  uniDefine;

{ EnemyAircraft_Straight }

procedure EnemyAircraft_Straight.calcShootInterval;
begin
  shootInterval := Round((30.0 + FRAND * 90.0) / uniGlobal.speedAdj);
end;

constructor EnemyAircraft_Straight.Create(et: EnemyType; p: array of Single; randFact: Single);
begin
  inherited Create(et, p, randFact);
  init(p, randFact);
end;

destructor EnemyAircraft_Straight.Destroy;
begin
  //inherited;
end;

procedure EnemyAircraft_Straight.init;
begin
  inherited init;
end;

procedure EnemyAircraft_Straight.init(p: array of Single; randFact: Single);
var
  frand: Single;
begin
  inherited init(p, randFact);

  frand := uniDefine.FRAND * randFact;

  damage := -110.0 * uniGlobal.gameSkill;
  baseDamage := -110.0 * uniGlobal.gameSkill;
  size[0] := 0.75;
  size[1] := 1.02;
  collisionMove := 0.5;
  vel[1] := -0.046 - frand * 0.04;
end;

procedure EnemyAircraft_Straight.move;
var
  _config: Config;
  hpos: PSingle;
begin
  //Config *config = Config::instance();
  _config := uniConfig.instance;

  if Boolean(target) then
    hpos := target.getPos
  else
    hpos := @pos;

  pos[1] := pos[1] + (uniGlobal.speedAdj * (vel[1] * uniGlobal.gameSkill));
  //	fprintf(stderr, "EnemyAircraft_Straight %p ... pos[1] := %g, vel[1] := %g\n", this, pos[1], vel[1]);
  Writeln('EnemyAircraft_Straight ', Self.ClassName, ' ... pos[1] := ', pos[1], ', vel[1] := ', vel[1]);

  if (pos[0] < -_config.screenBoundX) then pos[0] := -_config.screenBoundX;
  if (pos[0] > _config.screenBoundX) then pos[0] := _config.screenBoundX;
end;

//-- NOTE: Many of the firing rates are not adjusted by game->speedAdj
//-- so they will not be totally correct. Should be close enough for jazz, though.
//----------------------------------------------------------

procedure EnemyAircraft_Straight.update;
var
  s: Single;
  p: array[0..2] of Single;
begin
  //-- update age
  Inc(age);
  Dec(shootInterval);

  pos[0] := pos[0] + secondaryMove[0] * uniGlobal.speedAdj;
  pos[1] := pos[1] + secondaryMove[1] * uniGlobal.speedAdj;
  s := (1.0 - uniGlobal.speedAdj) + (uniGlobal.speedAdj * 0.7);
  secondaryMove[0] := secondaryMove[0] * s;
  secondaryMove[1] := secondaryMove[1] * s;
  move;

  //float	p[3] := { pos[0], pos[1], pos[2] };
  p[0] := pos[0];
  p[1] := pos[1];
  p[2] := pos[2];

  if (shootInterval < 10) then
    preFire := (10 - shootInterval) / 10.0
  else
    preFire := 0.0;
  if not Boolean(shootInterval) then
  begin
    calcShootInterval;
    p[1] := p[1] - 0.9;
    uniGlobal._enemyAmmo.addAmmo(0, p, shootVec);
  end;
end;

end.

